package controllers

import (
	beego "github.com/beego/beego/v2/server/web"
	"vip/models"
)

type VipController struct {
	beego.Controller
}
type JsonR struct {
	Code int         `json:"code"`
	Msg  string      `json:"msg"`
	Data interface{} `json:"data"`
}

func (c *VipController) Up() {
	id, _ := c.GetInt("id")
	images := c.GetString("images")
	name := c.GetString("name")
	tel := c.GetString("tel")
	lx := c.GetString("lx")
	ly := c.GetString("ly")
	money, _ := c.GetFloat("money")
	zt := c.GetString("zt")
	time := c.GetString("time")
	allvip := models.Vip{
		Id:     id,
		Images: images,
		Name:   name,
		Tel:    tel,
		Lx:     lx,
		Ly:     ly,
		Money:  money,
		Zt:     zt,
		Time:   time,
	}
	err := models.DB.Save(&allvip).Error
	if err != nil {
		c.Data["json"] = JsonR{
			Code: 0,
			Msg:  "修改失败",
			Data: nil,
		}
		c.ServeJSON()
		return
	} else {
		c.Data["json"] = JsonR{
			Code: 200,
			Msg:  "修改成功",
			Data: nil,
		}
		c.ServeJSON()
	}
}
func (c *VipController) List() {
	var allvip []models.Vip
	err := models.DB.Find(&allvip).Order("ACE").Error
	if err != nil {
		c.Data["json"] = JsonR{
			Code: 0,
			Msg:  "查询失败",
			Data: nil,
		}
		c.ServeJSON()
		return
	} else {
		c.Data["json"] = JsonR{
			Code: 200,
			Msg:  "查询成功",
			Data: allvip,
		}
		c.ServeJSON()
	}
}
